<?php

namespace app\common\model;

use think\Model;
use traits\model\SoftDelete;
use app\common\model\GoodsCategory;
class UserApply extends Model
{

    use SoftDelete;

    

    // 表名
    protected $name = 'ShopApply';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
    ];

    public function getLogoAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['logo']) ? $data['logo'] : '');
        return get_app_image_url($value);
    }

    public function getImageAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['image']) ? $data['image'] : '');
        if(!$value){ return  [];}
        $value=explode(',',$value);
        foreach ($value as $k=>&$v){
            $v=get_app_image_url($v);
        }
        return $value;
    }
    public function getCertificateImageAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['certificate_image']) ? $data['certificate_image'] : '');
        if(!$value){ return  [];}
        $value=explode(',',$value);
        foreach ($value as $k=>&$v){
            $v=get_app_image_url($v);
        }
        return $value;
    }
    public function getCorpSfzzAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['corp_sfzz']) ? $data['corp_sfzz'] : '');
        if(!$value){ return  [];}
        $value=explode(',',$value);
        foreach ($value as $k=>&$v){
            $v=get_app_image_url($v);
        }
        return $value;
    }


    /**
     * 详情
     * */
    public static function getInfo($id,$type=2){
//        $where['status']=2;
//        $where['type']=$type;
        $where['id']=$id;
        $info  = self::where($where)
            ->find();
        if($info['cate_id']){
            $GoodsCategory = GoodsCategory::where(['id'=>$info['cate_id']])->find();
            $info['cname']=$GoodsCategory['name'];
        }
        return $info;
    }


}
